<%@ Page Language="C#" AutoEventWireup="false" MasterPageFile="ScreenMasterPage.master" %>
<asp:Content ContentPlaceHolderID="Head" runat="server">

	<script type="text/javascript">
		window.top.importThemedOshControl(this, "Clock.htc");
		window.top.importCommonOshControl(this, "ChannelNumberInput.htc");

		var recorded = false;
		
		function window::onload()
		{
			screen.onKey.attach(this, onKey);
			screen.onCommand.attach(this, onCommand);
			screen.onShow.attach(null, onShow);
			screen.onAutoHide.attach(this, onAutoHide);
		}
		
		function window::onunload()
		{
			screen.onKey.detach(this, onKey);
			screen.onCommand.detach(this, onCommand);
			screen.onShow.detach(null, onShow);
			screen.onAutoHide.detach(this, onAutoHide);
		}
		
		function onShow()
		{
			if(screen.arguments != null)
			{
				channelNumber.value = (parseInt(screen.arguments) - parseInt("0"));
				screen.arguments = null;
			}
			channelNumber.className = "";
		}
		
		function onAutoHide(sender, event)
		{
			var num = channelNumber.value;
			channelNumber.value = null;
			channelNumber.className = "";

			if(num != null && num > 0 && !recorded)
			{
				if(osh.mediaController.moveToMediaByNumber(num))
					osh.mediaController.playCurrentMedia();
			}
			recorded = false;
		}
		
		function onKey(sender, event)
		{
			if(event.keyCode == Keys.VK_ENTER)
				onAutoHide(sender, event);
			else if(event.keyCode == Keys.VK_RECORD)
			{
				var num = channelNumber.value;
				if(num != null)
				{
					channelNumber.className = "record";
				
					var media = osh.mediaController.getCurrentMedia();
					if(media && Channel.isInstanceOfType(media))
					{
						media.setChannelNumber(num);
						recorded = true;
						screen.restartAutoHideTimer(1000);
					}
				}
			}
		}
		
		function onCommand(sender, event)
		{
			if(event.command && event.command.length == 1)
			{
				var keyCode = event.command.charCodeAt(0);
				if(keyCode >= Keys.VK_0 && keyCode <= Keys.VK_9)
				{
					if(!screen.getVisible())
						screen.show();

					osh.show();

					var e = window.top.document.createEventObject();
					e.keyCode = keyCode;
					channelNumber.processKey(this, e);
				}
			}
		}
	</script>

</asp:Content>
<asp:Content ContentPlaceHolderID="Body" runat="server">

	<osh:Clock mode="brief" />
		
	<osh:ChannelNumberInput id="channelNumber" format="{0}_" selected="true" />

</asp:Content>
